package game.display;

import game.MainController;
import game.Engine.Entity.Player;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;

public class PowerUpDisplay {
   private Rectangle r;
   private int magicType;

   public PowerUpDisplay(Rectangle rec, int magicType) {
      this.r = rec;
      this.magicType = magicType;
   }

   public void update(Graphics g, Color c) {
      // Sets the background to gray
      g.setColor(Color.gray);
      g.fillRect(r.x, r.y, r.width, r.height);

      Player p = MainController.gameEngine.getPlayer(MainController.getID());
      if (p != null) {
         // if the player has the magic, draw the color
         if (p.getPlayerMagic(magicType))
            g.setColor(c);
         else
            g.setColor(Color.gray);// Draw a gray square saying that they don't
                                   // have the magic

         long timeLeft = p.getMagicTime(magicType);
         if (timeLeft == 0)
            g.fillRect(r.x, r.y, r.width, r.height);
         else {
            long maxTime = p.getMaxMagicTime(magicType);
            double percentChange = (double) timeLeft / (double) maxTime;
            g.fillRect(r.x, r.y + (int) (percentChange * r.height), r.width,
                  r.height - (int) ((percentChange) * r.height));
         }
      }
   }
}
